Skip to content

fix(core): make LikeC4 patching string- and comment-aware and default to model-edits - #410

Merged
parse merged 5 commits into
mainfrom
fix/likec4-patching-robustness
Nov 18, 2026
Merged

parse merged 5 commits into
mainfrom
fix/likec4-patching-robustness

Conversation

@parse

@parse parse commented Nov 17, 2026 •

Copy link
Copy Markdown
Contributor

Stacked on #409.

What changed

  • Dotted new components: written as extend parent { child = ... } in text patching. Before, a.b.c = service ... was invalid DSL and the whole patch, relationships included, was dropped.
  • One DSL scanner (adapters/dsl-scanner.ts): masks strings (', ", ''') and comments before counting braces, so description 'a } b', // } and /* } */ no longer misplace inserts. // after : (unquoted link https://...) is not a comment.
  • Model block detection: model { at a statement start, after a BOM, or after {/; on the same line (workspace "x" { model {). extend x.datamodel { and elements named model no longer match.
  • AI patch pre-check: compares the brace delta against the original and requires each inserted block to appear as a contiguous run of lines. A patch that re-parents cache out of its extend block is now rejected.
  • Default strategy: adapter.likec4.patchStrategy defaults to model-edits; text patching stays the fallback. In multi-project workspaces model-edits writes into the selected project, or falls back to text when none is selected.
  • Other: -> inside comments or strings no longer drives target-file choice; inserts into an empty or one-line model block are indented. Structurizr uses the same scanner with double quotes and # comments.
  • Docs: ADR-012 amendment, regenerated config schemas, configuration reference.

Behaviour changes

  • model-edits is the default LikeC4 patch strategy.
  • Text insertion targets the last model block in a file.

Review follow-ups

  • // and /* start a comment only at a token boundary, so unquoted URLs such as link https://x.io/api/* no longer mask braces.

Checks

Check Result
check:ci pass
knip pass
Tests 1092 core + 10 cli pass, incl. an end-to-end dotted-component patch through the real LikeC4 validator

@coderabbitai

coderabbitai Bot commented Nov 17, 2026 •

Copy link
Copy Markdown

Warning

Review limit reached

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Next included review available in 57 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used the included review currently available.

Learn how review limits work.

Review configuration:

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 58a47a17-1720-4e45-b3f1-bb2a000138ca
Commits

Reviewing files that changed from the base of the PR and between 79e083a and 74e414d.

Files selected for processing: 24

  • packages/core/schemas/eroderc.schema.json
  • packages/core/src/adapters/__tests__/dsl-scanner-urls.test.ts
  • packages/core/src/adapters/__tests__/dsl-scanner.test.ts
  • packages/core/src/adapters/base-patcher.ts
  • packages/core/src/adapters/dsl-scanner.ts
  • packages/core/src/adapters/likec4/__tests__/deterministic-insert.test.ts
  • packages/core/src/adapters/likec4/__tests__/model-edits.test.ts
  • packages/core/src/adapters/likec4/__tests__/multi-file-workspace.test.ts
  • packages/core/src/adapters/likec4/__tests__/multi-project.test.ts
  • packages/core/src/adapters/likec4/__tests__/patcher-bidirectional.test.ts
  • packages/core/src/adapters/likec4/__tests__/patcher-dotted-e2e.test.ts
  • packages/core/src/adapters/likec4/__tests__/patcher-escaping.test.ts
  • packages/core/src/adapters/likec4/__tests__/patcher-format.test.ts
  • packages/core/src/adapters/likec4/__tests__/patcher-model-edits.test.ts
  • packages/core/src/adapters/likec4/__tests__/patcher-robustness.test.ts
  • packages/core/src/adapters/likec4/__tests__/patcher.test.ts
  • packages/core/src/adapters/likec4/model-edits.ts
  • packages/core/src/adapters/likec4/patcher.ts
  • packages/core/src/adapters/structurizr/__tests__/deterministic-insert.test.ts
  • packages/core/src/adapters/structurizr/patcher.ts
  • packages/core/src/utils/config.ts
  • packages/web/public/schemas/v0/eroderc.schema.json
  • packages/web/src/content/docs/docs/contributing/adrs/012-likec4-model-edits-via-diff-blocks.md
  • packages/web/src/content/docs/docs/reference/configuration.md
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

@parse
parse added this pull request to stack #414 November 17, 2026 17:21
@parse
parse force-pushed the fix/likec4-patching-robustness branch from 64892dd to 53682bb Compare November 17, 2026 17:49
@parse
parse marked this pull request as ready for review November 17, 2026 17:49
@parse
parse requested a review from a team as a code owner November 17, 2026 17:49
@greptile-apps

greptile-apps Bot commented Nov 17, 2026 •

Copy link
Copy Markdown

RetriggerView in GreptileConfidence Score: 4/5

[Medium impact] The PR reaches architecture-model patching and the analysis and check flows.

The comment-boundary issue should be fixed before merging.

Findings

  1. P1 Adjacent comments break text patches. ▶

Summary

This PR makes model patching aware of strings and comments and makes LikeC4 model edits the default.

  • LikeC4 patching tries model edits first and targets the selected project.
  • Text patching finds model blocks without counting braces in strings or comments.
  • Relationship deduplication distinguishes the relationship kinds that matter to each model format.
  • Component matching and analysis prompts use tighter rules for generated model changes.
  • The check and output flows use updated violation and diff-size rules.

No new findings.

Reviews (4) · Last reviewed commit: "fix(core): do not treat URL paths as com..." · Reviewed by Greptile

@parse
parse force-pushed the fix/likec4-patching-robustness branch 2 times, most recently from bd672b0 to 84bb5de Compare November 18, 2026 07:16
// inside an unquoted token. Unquoted URIs such as `link https://x.io/api/*` contain `//` and
// `/*`, and mistaking them for comments would hide every later closing brace. Real comments in
// models are always written after whitespace or a brace, so this is the safest boundary.
const commentMayStart = (at: number): boolean => at === 0 || /[\s{};]/.test(text.charAt(at - 1));

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Adjacent comments break text patches. commentMayStart rejects comments immediately after a closing quote, even though a = service 'A'// } is valid LikeC4. The scanner then treats the comment's } as the end of model. With the text strategy and no accepted AI patch, deterministicInsert splits that comment line at the brace, adds the relationships, and turns the commented brace into a real closing brace. Any following elements fall outside model, so validation rejects the whole patch. Recognize comments after quoted strings while keeping comment-like text inside unquoted URLs intact.

Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!

Base automatically changed from fix/small-correctness-fixes to main November 18, 2026 07:20
…g models

- Dotted new-component IDs now become `extend <parent> { <leaf> = ... }` in
  the text path, sharing componentDefinition with the model-edits diff block.
  Before, `a.b.c = service` failed validation and dropped the whole patch.
- Model blocks are found by a `model` keyword at line start followed by `{`,
  possibly on the next line, so `extend x.datamodel {` no longer counts.
- New dsl-scanner masks '...', "...", '''...''', // and /* */ before brace
  matching, used by deterministicInsert, quickValidatePatch and
  findTargetFile. Replaces closingBraceOnSameLine.
- quickValidatePatch checks multi-line entries line by line, and
  deterministicInsert re-indents them as a unit.
`adapter.likec4.patchStrategy` now defaults to `model-edits`; `text` stays
selectable and is still the fallback whenever model edits return no patch.
Tests about text patching pin `text` explicitly. Regenerates both config
schemas, updates the configuration reference and amends ADR-012.
Structurizr strings use double quotes only and lines starting with # are comments, so an apostrophe such as "# Bob's workspace" no longer masks the model block. quickValidatePatch takes the format's scan options as an optional fourth argument. ADR-012 amendment now notes that text-path insertedLines can still differ from LikeC4's placement under model-edits.
- Keep // after : as part of an unquoted URI, not a line comment
- Find model blocks after a BOM and after { or ; on the same line
- Quick-validate by brace delta and require inserted entries as contiguous blocks
- Place the model-edits diff file in the selected LikeC4 project's folder
- Ignore -> in comments and strings when picking the target file
- Indent entries one level inside an empty or split model block
Comments now open only at a token boundary (line start, whitespace, or one
of { } ;), so unquoted URIs containing // or /* no longer hide later braces.
@parse
parse force-pushed the fix/likec4-patching-robustness branch from 84bb5de to 74e414d Compare November 18, 2026 07:20
@parse
parse merged commit d9d9097 into main Nov 18, 2026
10 checks passed
@parse
parse deleted the fix/likec4-patching-robustness branch November 18, 2026 07:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant